<?php
namespace app\admin\controller;
use think\Db;
use think\Request;
class Orders extends Base {
    /**
     *订单列表
    */
    public function ordersList(){
        $this->isLogin();
        $row = Db::table("orders")
            ->where("is_del = 0")
            ->field('users.user_id,users.user_name,users.user_photo,orders.order_id,
                    orders.order_status,orders.total_money,orders.is_pay,orders.order_type,
                    orders.order_time,courses.courses_name,courses.courses_photo')
            ->join('users','users.user_id = orders.user_id')
            ->join('courses','orders.courses_id = courses.courses_id')
            ->select();
           $this->view->assign("row",$row);
            return view();

    }

    /**
     * 订单删除
    */
    public function ordersDel(){
        $this->isLogin();
        $request = Request::instance()->get();
        $id = $request['id'];
        $row = Db::table('orders')->where("order_id = $id")->update(['is_del' => 1]);
        if($row>0){
            echo 1;
        }else{
            echo 2;
        }

    }

    /**
     *修改订单
    */
    public function ordersUpdate(){
        $this->isLogin(); 
        $request = Request::instance()->get();
        $id = $request['id'];
        $this->view->assign("id",$id);
        return view();
    }

    /**
     *修改订单
    */
    public function ordersUpdates(){
        $this->isLogin();
        $request = Request::instance()->post();
        $id = $request['id'];
        $state = $request['state'];
        $row = Db::table('orders')->where("order_id = $id")->update(['order_status' => $state]);
        if($row>0){
            $this->success("修改成功",url('admin/orders/ordersList'),3);
        }else{
            $this->error('修改失败',url('admin/orders/ordersList'),3);
        }
    }

}